#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 55;

inline __int128 read(){
    __int128 x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

inline void print(__int128 x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}

int n;
__int128 dp[N][N];
__int128 w[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ )
        w[i] = read();
    
    for (int len = 3; len <= n; len ++ )
        for (int l = 1; l + len - 1 <= n; l ++ )
        {
            int r = l + len - 1;
            dp[l][r] = 1e30;
            for (int k = l + 1; k < r; k ++ )
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + w[l] * w[r] * w[k]);
        }
        
    print(dp[1][n]);
    
    return 0;
}
